/*****************************************************************************/
exports.controllers={
	admin_roles: function(space) {
		if (!space.roles.users) return "Access denied";
		var mode=space.fields.mode||"list";
		switch (mode) {
			case "list":
				space.all_roles=space.site.sql.execute_and_fetch("roles/list");
				return space.views.process("widgets/admin_roles/list",space);
			case "save":
				var hashes=space.functions.parse_grids(space).roles;
				space.functions.save_grid(space,hashes,"roles",{
					existing: function(hash,id) {return {}},
					insert: function(hash,id) {},
					update: function(hash,id) {hash.role_id=id;},
					delold: function(hash,id) {hash.role_id=id;}
				});
				return JSON.stringify({redirect:{url:space.action+"?mode=ok"}});
			case "ok":
				return space.views.process("widgets/save_ok",space);
		}
	}
};

/*****************************************************************************/
